package com.zyx.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyx.commonutils.R;
import com.zyx.eduservice.entity.EduCourse;
import com.zyx.eduservice.entity.EduTeacher;
import com.zyx.eduservice.service.EduCourseService;
import com.zyx.eduservice.service.EduTeacherService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zyx
 * @version 1.0
 * @date 2022/1/8 008 9:16
 */
@RestController
@CrossOrigin
@RequestMapping("eduservice/indexfront")
public class IndexFrontController {

    @Resource
    private EduCourseService eduCourseService;

    @Resource
    private EduTeacherService eduTeacherService;

    @GetMapping("index")
    public R index(){

        //查询前8个热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> list = eduCourseService.list(wrapper);

        //查询前4个名师
        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");
        List<EduTeacher> eduTeacher = eduTeacherService.list(teacherWrapper);

        return R.ok().data("eduList",list).data("teacherList",eduTeacher);
    }

}
